/**
 * 
 */

/**
 * @author terratack
 *
 */
public class Card {
	private char[] spr = {'2','3','4','5','6','7','8','9','1','J','Q','K','A'};
	private int[] spade = new int[13];
	private int[] heart = new int[13];
	private int[] diamond = new int[13];
	private int[] club = new int[13];
	public int[] cards = new int[13];
	public int player_score;
	Card(Player player, boolean pass){
		if(pass == true)
		{
			player_score = -1;
		}
		else
		{
		char help, help2;
		player_score = 0;
		for(int i = 0; i < 13; i++){
			spade[i] = 0;
			heart[i] = 0;
			diamond[i] = 0;
			club[i] = 0;
			cards[i] = 0;
		}
		for(int i = 0; i < 5; i++){
			help = player.cards_in_hand[i].charAt(0);
			help2 = player.cards_in_hand[i].charAt(2);
			if(help2 == '-') help2 = player.cards_in_hand[i].charAt(3);
			if(help2 == 's'){
				for(int j = 0; j < 13; j++){
					if(help == spr[j]) spade[j] = 1;
				}
			}
			else if(help2 == 'h'){
				for(int j = 0; j < 13; j++){
					if(help == spr[j]) heart[j] = 1;
				}
			}
			else if(help2 == 'd'){
				for(int j = 0; j < 13; j++){
					if(help == spr[j]) diamond[j] = 1;
				}
			}
			else if(help2 == 'c'){
				for(int j = 0; j < 13; j++){
					if(help == spr[j]) club[j] = 1;
				}
			}
		}
		for(int i = 0; i < 13; i++){
			cards[i] = spade[i] + heart[i] + diamond[i] + club[i];
		}
		for(int i = 0; i < 13; i++){
			if(spade[i] == 1) player_score += i+1;
			if(heart[i] == 1) player_score += i+1;
			if(diamond[i] == 1) player_score += i+1;
			if(club[i] == 1) player_score += i+1;
		}
		poker();
		if(player_score < 5000) four_of_kind();
		if(player_score < 5000) full();
		if(player_score < 5000) flush();
		if(player_score < 5000) straight();
		if(player_score < 5000) three_of_kind();
		if(player_score < 5000) two_pair();
		if(player_score < 5000) pair();
		if(player_score < 5000) player_score = 0;
	}
	}
	private void poker(){
		int help = 0;
		for(int i = 0; i < 13; i++){
			if(spade[i] == 1) help++;
			else help = 0;
			if(help == 5){ player_score += 20000; return;}
		}
		help = 0;
		for(int i = 0; i < 13; i++){
			if(heart[i] == 1) help++;
			else help = 0;
			if(help == 5){ player_score += 20000; return;}
		}
		help = 0;
		for(int i = 0; i < 13; i++){
			if(diamond[i] == 1) help++;
			else help = 0;
			if(help == 5){ player_score += 20000; return;}
		}
		help = 0;
		for(int i = 0; i < 13; i++){
			if(club[i] == 1) help++;
			else help = 0;
			if(help == 5){ player_score += 20000; return;}
		}
		help = 0;
	}
	private void four_of_kind(){
		for(int i = 0; i < 13; i++){
			if(spade[i] == 1 && heart[i] == 1 && diamond[i] == 1 && club[i] == 1){ player_score += 18000; return;}
		}
	}
	private void full(){
		int two = 0,three = 0;
		for(int i = 0; i < 13; i++){
			if(spade[i] + heart[i] + diamond[i] + club[i] == 3) three = 1;
			if(spade[i] + heart[i] + diamond[i] + club[i] == 2) two = 1;
			
			if(three == 1 && two == 1){ player_score += 16000; return;}
		}
	}
	private void flush(){
		int[] help = new int[4];
		for(int i = 0; i < 13; i++){
			help[0] += spade[i];
			help[1] += heart[i];
			help[2] += diamond[i];
			help[3] += club[i];
			if(help[0] == 5 || help[1] == 5 || help[2] == 5 || help[3] == 5){ player_score += 14000; return;}
		}
	}
	private void straight(){
		int help = 0;
		for(int i = 0; i < 13; i++){
			if(spade[i] + heart[i] + diamond[i] + club[i] == 1) help += 1;
			else help = 0;
			if(help == 5){ player_score += 12000; return;}
		}
	}
	private void three_of_kind(){
		for(int i = 0; i < 13; i++){
			if(spade[i] + heart[i] + diamond[i] + club[i] == 3){ player_score += 10000; return;}
		}
	}
	private void two_pair(){
		int help = 0;
		for(int i = 0; i < 13; i++){
			if(spade[i] + heart[i] + diamond[i] + club[i] == 2) help++;
			if(help == 2){ player_score += 8000; return;}
		}
	}
	private void pair(){
		for(int i = 0; i < 13; i++){
			if(spade[i] + heart[i] + diamond[i] + club[i] == 2){ player_score += 6000; return;}
		}
	}	
}
